<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/19
 * Time: 12:49
 */
include "../classes/logincheck.php";
include('../classes/conn.php');
$class=$_POST['class'];
$sec=$_POST['sec'];
$sub=$_POST['sub'];
if(islogin()!="teacher_login"){
    die('error');
}

$name=iconv("UTF-8","GB2312",$_FILES['attach']['name']);

$dir="../Files/". $_SESSION['t_num'] . "/courseware/" . $name;

if(file_exists($dir)){
    die('file_exist');
}
$callback=move_uploaded_file($_FILES['attach']['tmp_name'],
    $dir);

$dir="requests/Files/". $_SESSION['t_num'] . "/courseware/" . $_FILES['attach']['name'];
$query="insert into courseware (name,class,section,subsection,attach) values ('{$_FILES['attach']['name']}','{$class}','{$sec}','{$sub}','{$dir}')";
$res=mysql_query($query);
if($res){
    echo '1';
}
else echo '0';